package com.blkbox.javase.asynchronous.ex2;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class MyFutureTaskTest {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void main(String[] args) {
		FutureTask ft = new FutureTask<String>(new Callable() {
			public Object call() throws Exception {

				Thread.sleep(1000);
				System.out.println("In");
				return "p2";
			}
		});

		ExecutorService executor = Executors.newCachedThreadPool();
		executor.execute(ft);
		
		try {
			String result = (String) ft.get();
			System.out.print("result is ");
			System.out.println(result);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
